using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;

using Toenda.Foundation.Globalization;
using Toenda.Foundation.Globalization.Holiday.HolidayCalenderFactories;

namespace Toenda.Foundation.Globalization.Holiday {
	/// <summary>
	/// Implements a holiday calendar
	/// </summary>
	public static class HolidayCalendar {
		/// <summary>
		/// Checks if a date is a weekend date, calles the calender class.
		/// </summary>
		/// <param name="date"></param>
		/// <returns></returns>
		public static bool IsWeekend(DateTime date) {
			if(date.DayOfWeek == DayOfWeek.Saturday
			|| date.DayOfWeek == DayOfWeek.Sunday) {
				return true;
			}
			else {
				return false;
			}
		}

		/// <summary>
		/// Checks if a day is a holiday
		/// </summary>
		/// <param name="date"></param>
		/// <param name="code"></param>
		/// <returns></returns>
		public static bool IsHoliday(DateTime date) {
			return IsHoliday(date, new CountryCode() { TwoLetterISOLanguageName = "DE" });
		}

		/// <summary>
		/// Checks if a day is a holiday
		/// </summary>
		/// <param name="date"></param>
		/// <param name="code"></param>
		/// <returns></returns>
		public static bool IsHoliday(DateTime date, CountryCode code) {
			HolidayCalendarFactory factory = null;

			switch(code.TwoLetterISOLanguageName) {
				case "DE":
					factory = GermanHolidayCalendarFactory.GetInstance(date.Year, HolidayEventType.Banking);
					break;

				case "US":
					factory = AmericanHolidayCalendarFactory.GetInstance(date.Year, HolidayEventType.Banking);
					break;

				case "GB":
					factory = EnglandHolidayCalendarFactory.GetInstance(date.Year, HolidayEventType.Banking);
					break;

				case "FR":
					factory = FrenchHolidayCalendarFactory.GetInstance(date.Year, HolidayEventType.Banking);
					break;

				case "CH":
					factory = SwissHolidayCalendarFactory.GetInstance(date.Year, HolidayEventType.Banking);
					break;

				default:
					return IsHoliday(date, code);
			}

			return factory.IsHoliday(date);
		}

		/// <summary>
		/// Checks if a day is a holiday
		/// </summary>
		/// <param name="date"></param>
		/// <param name="codeList"></param>
		/// <returns></returns>
		public static bool IsHoliday(DateTime date, List<CountryCode> codeList) {
			if(codeList != null) {
				foreach(CountryCode code in codeList) {
					if(IsHoliday(date, code)) {
						return true;
					}
				}
			}

			return false;
		}
	}
}
